// 蜂窝蜜造平台生成代码，如手工更改，请添加到 .beeignore 忽略生成

package com.fowo.api.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.common.config.CacheConfig;
import com.fowo.api.common.excel.ExcelConfig;
import com.fowo.api.common.model.OptionItem;
import com.fowo.api.common.util.ContextHolder;
import com.fowo.api.common.util.ResponseUtils;
import com.fowo.api.entity.Warehouse;
import com.fowo.api.entity.WarehouseBin;
import com.fowo.api.flow.entity.WorkFlow;
import com.fowo.api.flow.service.WorkFlowService;
import com.fowo.api.mapper.WarehouseBinMapper;
import com.fowo.api.mapper.WarehouseMapper;
import com.fowo.api.model.warehouse.WarehouseFBABinVo;
import com.fowo.api.model.warehouse.WarehouseItemVo;
import com.fowo.api.model.warehouse.WarehouseLocalAndOverseasVo;
import com.fowo.api.model.warehouse.WarehouseSearchParamPo;
import com.fowo.api.model.warehouse.WarehouseVo;
import com.fowo.api.model.warehouse.bin.WarehouseBinSearchParamPo;
import com.fowo.api.model.warehouse.bin.WarehouseBinVo;
import com.fowo.api.service.WarehouseBinService;
import com.fowo.api.service.WarehouseService;
import com.fowo.api.sys.model.SysDictAllItem;
import com.fowo.api.sys.service.SysDictService;
import com.fowo.api.user.model.JwtUserInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 仓库 服务实现类
 * @author 蜂窝蜜造平台 配置人：王阳阳，李玉娇
 */
@Service
@Slf4j
@DS("ds24")
public class WarehouseServiceImpl
  extends WarehouseBaseServiceImpl{
    @Resource
    private WarehouseBinServiceImpl warehouseBinService;
    @Resource
    private SysDictService sysDictService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Long create(WarehouseVo model) throws Exception {
        Warehouse one = this.getOne(Wrappers.<Warehouse>query().lambda().eq(Warehouse::getName, model.getName()));
        Assert.isNull(one,model.getName()+"已存在");
        Long aLong = super.create(model);
        //默认创建库位
        AddWarehouse(aLong);
        return aLong;
    }

    public void AddWarehouse(Long aLong) throws Exception {
        //可用 5   次品6  待检暂存1   可用暂存2  次品暂存3  拣货暂存4   上架暂存 7   可用在途暂存8  次品在途暂存9
        List<SysDictAllItem> scm00018 = sysDictService.getDictItems("SCM00018");
        List<WarehouseBin> WarehouseBins=new ArrayList<>();
        scm00018.forEach(x->{
            WarehouseBin model =new WarehouseBin();
            model.setUseType("2");
            model.setStatus("1");
            model.setStorageBin(x.getItemText());
            model.setSysType("0");
            model.setWarehouseId(aLong);
            model.setType(x.getItemValue());
            WarehouseBins.add(model);
        });
        warehouseBinService.saveBatch(WarehouseBins);
    }

}
